package com.mjsoftking.aopapp.aop.aspect;

import android.text.TextUtils;

import com.mjsoftking.aopapp.Constants;
import com.mjsoftking.aopapp.aop.anno.CheckAuth;
import com.mjsoftking.aopapp.event.NoLoginEvent;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.greenrobot.eventbus.EventBus;

/**
 *
 */
@Aspect
public class AuthAspect {


    /**
     * 拦截检查是否登录过
     */
    @Around(value = "BaseAspect.checkAuthAnnotation(checkAuth)")
    public Object around(ProceedingJoinPoint joinPoint, CheckAuth checkAuth) throws Throwable {
        if (TextUtils.isEmpty(Constants.TOKEN)) {
            //发送事件，也可用广播方式实现
            EventBus.getDefault().post(new NoLoginEvent());
            return null;
        }

        return joinPoint.proceed();
    }

}
